package com.flyou.ccnucenter.ui.frgment;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.flyou.ccnucenter.R;

/**
 * MyUser: special
 * Date: 13-12-22
 * Time: 下午3:28
 * Mail: specialcyci@gmail.com
 */
public class WeiChatFragment extends BaseFragment implements View.OnClickListener {


    private View parentView;
    private WebView webView;

    @Override
    protected View onCreatView(LayoutInflater inflater, ViewGroup container) {

        parentView = inflater.inflate(R.layout.weichat_fragment, container, false);
        return parentView;
    }

    @Override
    protected void initData() {
        String url = context.getIntent().getStringExtra("url");
        webView.loadUrl(url);



    }

    @Override
    protected void initView() {

        this.webView = (WebView) parentView.findViewById(R.id.vebView);
        webView.setBackgroundColor(0);
        WebSettings webSettings = webView.getSettings();
        webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setBlockNetworkImage(false);
        webSettings.setDefaultTextEncodingName("utf-8");
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setTextSize(WebSettings.TextSize.NORMAL);
        webView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {

                super.onPageFinished(view, url);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(context, "加载失败", Toast.LENGTH_SHORT).show();
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });

    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.titlebar_rl_back:
                if (webView.canGoBack()){
                    webView.goBack();
                }
                else {

                }
                break;

        }
    }




}
